//
//  ECCourseOrderModel.m
//  Edu_iOS2018
//
//  Created by yanyan on 2018/1/13.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#import "ECCourseOrderModel.h"
#import "CYDateFormatter.h"
#import "CYDataHelper.h"
@implementation ECCourseOrderModel
- (instancetype)initWithObject:(id)orderDataOfList
{
    if (self = [super init]) {
        self.orderId = [orderDataOfList valueForKey:@"id"];
        self.orderSN = [orderDataOfList valueForKey:@"sn"];
        self.orderState = [orderDataOfList valueForKey:@"status"];

        self.mo_course = [[CourseModel alloc]initWithObject:[orderDataOfList objectForKey:@"courses"]];
        self.mo_course.deleted = [[orderDataOfList valueForKey:@"deleted"] boolValue];
        self.reviewed = [[orderDataOfList valueForKey:@"reviewed"] boolValue];
        self.totalPrice = [orderDataOfList valueForKey:@"totalPrice"];
    }
    return self;
}
-(instancetype)initWithDetailObject:(id)orderDetailData{
    if (self = [super init]) {
        self.orderId = [orderDetailData valueForKey:@"id"];
        self.orderSN = [orderDetailData valueForKey:@"sn"];
        self.orderState = [orderDetailData valueForKey:@"status"];
        
        self.mo_course = [[CourseModel alloc]initWithObject:[orderDetailData objectForKey:@"courses"]];
        self.mo_course.deleted = [CYDataHelper isNull:[orderDetailData valueForKey:@"deleted"]]? NO :[[orderDetailData valueForKey:@"deleted"] boolValue];
        self.reviewed = [[orderDetailData valueForKey:@"reviewed"] boolValue];
        self.totalPrice = [orderDetailData valueForKey:@"totalPrice"];
        self.createdTime = [orderDetailData valueForKey:@"createdTime"];
        if ([self.orderState isEqualToString:@"paid"]) {
            self.paidTime = [orderDetailData valueForKey:@"paidTime"];
            if ([[orderDetailData valueForKey:@"payment"] isEqualToString:@"alipay"]) {
                self.payment = @"支付宝支付";
            } else {
                self.payment = @"微信支付";
            }
        } else {
            self.paidTime = nil;
            self.payment = nil;
        }
    }
    return self;
}

@end
